# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=astor
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.8.1
pkgrel=4
pkgdesc='Read/rewrite/write Python ASTs (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://astor.rtfd.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-nose")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("${_realname}-$pkgver.tar.gz::https://github.com/berkerpeksag/astor/archive/$pkgver.tar.gz")
sha512sums=('8917898e284fb5e5855a05f8e3f1c8925c4128d2a87f67f0334914d4d3c54b53c4f0cadd04d632a7bcaf3438db7edf2d989b07a9576637c0dce6c16e85c60f83')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  nosetests || warning "https://github.com/berkerpeksag/astor/issues/146"
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
